package com.vm.osm.business.service.omp.impl;

import com.vm.osm.business.dto.omp.logic_prop_relas.LogicProp;
import com.vm.osm.business.dto.omp.logic_prop_relas.RspGetByLogicDeviceId;
import com.vm.osm.business.service.omp.IOmpLogicPropRelasService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.List;

/**
 * 逻辑节点类型属性服务实现类
 *
 * @author Xuerong Xue
 */
@Service
public class OmpLogicPropRelasServiceImpl implements IOmpLogicPropRelasService {
    private static final Logger LOG = LoggerFactory.getLogger(OmpLogicPropRelasServiceImpl.class);
    @Value("${omp_api_url}")
    private String OMP_API_URL;
    @Autowired
    private RestTemplate restTemplate;

    @Override
    public List<LogicProp> getByLogicDeviceId(String logic_device_id) {
        try {
            LOG.info("【逻辑节点类型属性】（根据逻辑节点类型Id获取）logic_device_id={}", logic_device_id);
            if (StringUtils.isEmpty(logic_device_id)) return Collections.emptyList();
            String URL = OMP_API_URL + "/omp/v1.0/logic_prop_relas/" + logic_device_id + "/logic_prop_relas/dn_props?page_num=1&page_size=1000";
            ResponseEntity<RspGetByLogicDeviceId> entity = restTemplate.getForEntity(URL, RspGetByLogicDeviceId.class);
            return entity.getBody().data_list;
        } catch (Exception e) {
            LOG.error("【逻辑节点类型属性】（根据逻辑节点类型Id获取）异常", e);
            return null;
        }
    }
}
